<template>
	<view class="myOrder">
		<u-sticky bgColor="#fff">
			<u-tabs
				:current="current"
				:scrollable="false"
				:list="tabNav"
				@click="clickTab"
				inactiveStyle="font-size: 24rpx;"
				lineColor="#E54E4E"
				itemStyle="height: 88rpx;"
			></u-tabs>
		</u-sticky>
		<view class="container">
			<j-orderList jfen :list="list" @btns="clickbtn"></j-orderList>
			<u-loadmore :status="status" />
		</view>
		<u-modal :show="modal" title="确定取消该订单吗？" @close="modal = false" :closeOnClickOverlay="true">
			<view class="u-modal-btnbox" slot="confirmButton">
				<button @click="modal = false">取消</button>
				<button @click="del">确认</button>
			</view>
		</u-modal>
	</view>
</template>

<script>
import API from '@/common/api';
export default {
	name: 'myOrder',
	data() {
		return {
			current: 0,
			modal: false,
			status: '',
			tabNav: [
				{
					name: '全部',
					val:0
				},
				{
					name: '待发货',
					val:2
				},
				{
					name: '待收货',
					val:3
				},
				{
					name: '已完成',
					val:5
				}
			],
			list: [],
			tempItem: {},
			paging: {
				page: 1,
				pagenum: 20
			},
			nowType:0,
			total: 0
		};
	},
	onLoad(data) {
		if (data.hasOwnProperty('current')) {
			this.current = Number(data.current);
		}
	},
	onShow() {
		this.reset();
		this.init();
	},
	onReachBottom() {
		if (this.status === 'nomore') return;
		this.init();
	},
	methods: {
		clickbtn(flag, item) {
			console.log(flag, item);
			this.tempItem = item;
			switch (flag) {
				case 0:
					this.j_modal(
						'确认取消订单吗？',
						() => {
							this.qx_order(item);
						},
						true
					);
					break;
				case 1:
					this.toNav(`jifenshangcheng/jforderDetails?id=${item.id}&jfen=${true}`);
					break;
				case 2:
					this.qxpop = true;
					break;
				case 3:
					this.toNav(`jifenshangcheng/jforderDetails?id=${item.id}&jfen=${true}`);
					break;
				case 4:
					this.toNav(`pinglun/pinglun?id=${item.id}&jfen=${true}`);
					break;
				default:
					break;
			}
		},

		qx_order(item) {
			this.$http
				.getJson('orders_qxOrder', {
					order_id: item.id
				})
				.then((res) => {
					this.msg(res.message);
					if (res.code == 1) {
						this.reset();
						this.init();
					}
				});
		},

		init(status = 0) {
			this.status = 'loading';
			API.getJson('orders_lists', { ...this.paging, scene: this.nowType, if_jifen: 1 }).then((res) => {
				const { code, data, message } = res;
				if (code === 1) {
					if (data.length !== 0) this.list = this.list.concat(data);
					if (this.paging.pagenum === data.length) {
						this.paging.page += 1;
						this.status = 'loadmore';
					} else {
						this.status = 'nomore';
					}
				}
			});
		},
		reset() {
			this.paging.page = 1;
			this.list = [];
		},
		clickTab(e) {
			this.nowType = e.val;
			this.reset();
			this.init();
		}
	}
};
</script>

<style lang="less" scoped>
.myOrder {
	.u-modal-btnbox {
		button {
			border-radius: 8rpx 8rpx 8rpx 8rpx;
		}
	}
	.container {
		padding: 16rpx 32rpx 32rpx;
	}
}
</style>
